import { createRouter ,createWebHashHistory} from 'vue-router'
import {sessionStorage} from "../utils/storage";


const routes = [
  {
    path:'/',
    redirect:{
      path:'/login'
    },
    children:[
      {
        path:'login',
        component:()=>import('@/components/login/index.vue')
      },
      {
        path:'home',
        component:()=>import('@/components/layout/layout.vue'),
      }
    ]
  },
 
]

const router = createRouter({
  history:createWebHashHistory(),
  routes
})

// router.beforeEach((to, from, next) => {
//   if (to.path === '/login') next()
  
//   const tokenStr = sessionStorage.get('token',false)
//   // 增加判断条件
//   if (!tokenStr && to.path !== '/login'){
//     console.log(tokenStr)
//     return next('/login')
//   }
//   next()
// })
export default router